package acwing._1_1AlgorithmBasic._3SearchGraph;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._3SearchGraph
 * @File : Q0854.java
 * @Author : WangRuoyu
 * @Date : 2023/4/3 9:59
 */

import java.io.*;

public class Q0854 {
    static int n;
    static int m;
    static int k;
    static int[][] dis;

    static void floyd() {
        for (int l = 1; l <= n; ++l) {
            for (int i = 1; i <= n; ++i) {
                for (int j = 1; j <= n; ++j) {
                    dis[i][j] = Math.min(dis[i][j], dis[i][l] + dis[l][j]);
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");

        n = Integer.parseInt(words[0]);
        m = Integer.parseInt(words[1]);
        k = Integer.parseInt(words[2]);

        dis = new int[n + 1][n + 1];

        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (i == j) dis[i][j] = 0;
                else dis[i][j] = 0x3f3f3f3f;
            }
        }

        for (int i = 0; i < m; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            int c = Integer.parseInt(words[2]);
            dis[a][b] = Math.min(c, dis[a][b]);
        }

        floyd();

        for (int i = 0; i < k; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            if (dis[a][b] > 0x3f3f3f3f / 2) {
                wr.write("impossible\n");
            } else {
                wr.write(dis[a][b] + "\n");
            }
        }
        wr.flush();
    }
}

